
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module kefu.session
* @author: Hjava
* @description: 新客服模块消息外包
* @since: 2018-07-22 19:57:46
*/
var kefu_constant_1 = __webpack_require__(/*! _kefu/kefu.constant */ "./src/core/kefu/kefu.constant.ts");
var uuid_1 = __webpack_require__(/*! _util/uuid */ "./src/core/utils/uuid.ts");
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var bufferType_1 = __webpack_require__(/*! _util/bufferType */ "./src/core/utils/bufferType.ts");
var deviceInfo_1 = __webpack_require__(/*! _util/deviceInfo */ "./src/core/utils/deviceInfo.ts");
var timer_1 = __webpack_require__(/*! _util/timer */ "./src/core/utils/timer.ts");
var KFSession = {};
KFSession.KFSendMsgReq = protocol_1.default.Response.extend({
    category: 'KF',
    uri: kefu_constant_1.default.KF.URI_KF_SEND_MSG_REQ,
    init: function () {
        this.uri = kefu_constant_1.default.KF.URI_KF_SEND_MSG_REQ;
        // 设备类型
        this.deviceType = deviceInfo_1.default.deviceType;
        // 客户端消息ID
        this.msgUuid = uuid_1.default.next();
        // 消息服务端ID
        this.msgId = 0;
        // 发送人UID
        this.fromUid = 0;
        // 接收群UID
        this.toUid = 0;
        // 业务ID
        this.toAppId = 1;
        // 消息类型
        this.type;
        // 消息内容
        this.message;
        // 发送人名称//nickname
        this.fromName = '';
        // 消息产生时间
        this.cts = timer_1.default.get();
        // 自动重发次数
        this.retries = 0;
        // 消息方向: 1表示个人向客服载体发消息，2表示客服载体向个人发消息
        this.direction = 1;
        // 扩展信息
        this.extension = '';
        // 频道
        this.channel = 0;
        this.sessionSeqId = '';
    },
    initAfter: function () {
        this.message && (this.type = this.type || this.message.__type);
    },
    marshall: function () {
        this.push(this.deviceType, bufferType_1.default.BYTE);
        this.push(this.msgUuid, bufferType_1.default.STRING);
        this.push(this.msgId, bufferType_1.default.LONG);
        this.push(this.fromUid, bufferType_1.default.LONG);
        this.push(this.toUid, bufferType_1.default.LONG);
        this.push(this.toAppId, bufferType_1.default.SHORT);
        this.push(this.message.__type, bufferType_1.default.INT);
        this.push(this.message);
        this.push(this.fromName, bufferType_1.default.STRING);
        this.push(this.cts, bufferType_1.default.LONG);
        this.push(this.retries, bufferType_1.default.BYTE);
        this.push(this.direction, bufferType_1.default.BYTE);
        this.push(this.extension, bufferType_1.default.STRING);
        this.push(this.channel, bufferType_1.default.SHORT);
        this.push(this.sessionSeqId, bufferType_1.default.LONG);
    },
    unmarshall: function () {
        this.deviceType = this.popByte();
        this.msgUuid = this.popString();
        this.msgId = this.popLong().value();
        this.fromUid = this.popLong().value();
        this.toUid = this.popLong().value();
        this.toAppId = this.popShort();
        this.type = this.popInt();
        this.message = protocol_1.default.Message.fromBuffer(this.popBytes());
        this.fromName = this.popString();
        this.cts = this.popLong().value();
        this.retries = this.popByte();
        this.direction = this.popByte();
        this.extension = this.popString();
        this.channel = this.popShort();
        this.sessionSeqId = this.popLong().value();
    }
});
KFSession.KFSendMsgRes = protocol_1.default.Response.extend({
    category: 'KF',
    uri: kefu_constant_1.default.KF.URI_KF_SEND_MSG_RES,
    init: function () {
        // 返回结果码
        this.rescode = 0;
        // 客户端消息ID
        this.msgUuid = '';
        // 服务端消息ID
        this.msgId = '';
        // 消息创建时间
        this.cts = timer_1.default.get();
        // 设备类型
        this.deviceType = deviceInfo_1.default.deviceType;
        this.sessionSeqId = '';
    },
    marshall: function () {
        this.push(this.rescode, bufferType_1.default.INT);
        this.push(this.msgUuid, bufferType_1.default.STRING);
        this.push(this.msgId, bufferType_1.default.LONG);
        this.push(this.cts, bufferType_1.default.LONG);
        this.push(this.deviceType, bufferType_1.default.BYTE);
        this.push(this.sessionSeqId, bufferType_1.default.LONG);
    },
    unmarshall: function () {
        this.rescode = this.popInt();
        this.msgUuid = this.popString();
        this.msgId = this.popLong().value();
        this.cts = this.popLong().value();
        this.deviceType = this.popByte();
        this.sessionSeqId = this.popLong().value();
    }
});
KFSession.KFSendMsgKFReq = protocol_1.default.Response.extend({
    category: 'KF',
    uri: kefu_constant_1.default.KF.URI_KF_SEND_KF_MSG_REQ,
    init: function () {
        // 设备类型
        this.deviceType = deviceInfo_1.default.deviceType;
        // 客户端消息ID
        this.msgUuid = uuid_1.default.next();
        // 服务端消息ID
        this.msgId = '';
        // 发送人UID
        this.senderUid = '';
        // 接收人UID
        this.receiverUid = '';
        // 接收人APPID
        this.receiverAppId = '';
        // 客服载体ID
        this.bid = '';
        // 消息类型
        this.type = '';
        // 消息内容
        this.message = '';
        // 发送人名称
        this.fromName = '';
        // 消息产生时间
        this.cts = timer_1.default.get();
        // 推送类型
        this.pushType = 0;
        // 消息方向: 1表示个人向客服载体发消息，2表示客服载体向个人发消息
        this.direction = 1;
        // 自动重试次数，首次发送为0
        this.retries = 0;
        // 扩展信息
        this.extension = '';
        //频道
        this.channel = 0;
        this.sessionId = '';
        this.sessionSeqId = '';
    },
    initAfter: function () {
        this.message && (this.type = this.type || this.message.__type);
    },
    marshall: function () {
        this.push(this.deviceType, bufferType_1.default.BYTE);
        this.push(this.msgUuid, bufferType_1.default.STRING);
        this.push(this.msgId, bufferType_1.default.LONG);
        this.push(this.senderUid, bufferType_1.default.LONG);
        this.push(this.receiverUid, bufferType_1.default.LONG);
        this.push(this.receiverAppId, bufferType_1.default.SHORT);
        this.push(this.bid, bufferType_1.default.LONG);
        this.push(this.type, bufferType_1.default.INT);
        this.push(this.message);
        this.push(this.fromName, bufferType_1.default.STRING);
        this.push(this.cts, bufferType_1.default.LONG);
        this.push(this.pushType, bufferType_1.default.INT);
        this.push(this.direction, bufferType_1.default.BYTE);
        this.push(this.retries, bufferType_1.default.BYTE);
        this.push(this.extension, bufferType_1.default.STRING);
        this.push(this.channel, bufferType_1.default.SHORT);
        this.push(this.sessionId, bufferType_1.default.LONG);
        this.push(this.sessionSeqId, bufferType_1.default.LONG);
    },
    unmarshall: function () {
        this.deviceType = this.popByte();
        this.msgUuid = this.popString();
        this.msgId = this.popLong().value();
        this.senderUid = this.popLong().value();
        this.receiverUid = this.popLong().value();
        this.receiverAppId = this.popShort();
        this.bid = this.popLong().value();
        this.type = this.popInt();
        this.message = protocol_1.default.Message.fromBuffer(this.popBytes());
        this.fromName = this.popString();
        this.cts = this.popLong().value();
        this.pushType = this.popInt();
        this.direction = this.popByte();
        this.retries = this.popByte();
        this.extension = this.popString();
        this.channel = this.popShort();
        this.sessionId = this.popLong().value();
        this.sessionSeqId = this.popLong().value();
    }
});
KFSession.KFSendMsgKFRes = protocol_1.default.Response.extend({
    category: 'KF',
    uri: kefu_constant_1.default.KF.URI_KF_SEND_KF_MSG_RES,
    init: function () {
        // 返回结果码
        this.rescode = 0;
        // 客户端消息ID
        this.msgUuid = '';
        // 服务端消息ID
        this.msgId = '';
        // 消息创建时间
        this.cts = timer_1.default.get();
        // 设备类型
        this.deviceType = deviceInfo_1.default.deviceType;
        this.sessionSeqId = '';
    },
    marshall: function () {
        this.push(this.rescode, bufferType_1.default.INT);
        this.push(this.msgUuid, bufferType_1.default.STRING);
        this.push(this.msgId, bufferType_1.default.LONG);
        this.push(this.cts, bufferType_1.default.LONG);
        this.push(this.deviceType, bufferType_1.default.BYTE);
        this.push(this.sessionSeqId, bufferType_1.default.LONG);
    },
    unmarshall: function () {
        this.rescode = this.popInt();
        this.msgUuid = this.popString();
        this.msgId = this.popLong().value();
        this.cts = this.popLong().value();
        this.deviceType = this.popByte();
        this.sessionSeqId = this.popLong().value();
    }
});
KFSession.KFAckMsgs = protocol_1.default.Response.extend({
    category: 'KF',
    uri: kefu_constant_1.default.KF.URI_KF_ACK_MSGS,
    init: function () {
        // 设备类型
        this.deviceType = deviceInfo_1.default.deviceType;
        // 用户UID
        this.uid = 0;
        // 消息ID
        this.msgIds = [];
    },
    marshall: function () {
        this.push(this.deviceType, bufferType_1.default.BYTE);
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.msgIds);
    },
    unmarshall: function () {
        this.deviceType = this.popByte();
        this.uid = this.popLong().value();
        this.msgIds = this._popArrayLong();
    }
});
KFSession.KFSyncRead = protocol_1.default.Response.extend({
    category: 'KF',
    uri: kefu_constant_1.default.KF.URI_KF_SYNC_READ,
    init: function () {
        // 用户uid
        this.uid = '';
        // 用户设备类型
        this.deviceType = deviceInfo_1.default.deviceType;
        // 用户readTime列表
        this.syncReadItems = [];
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.deviceType, bufferType_1.default.BYTE);
        this.push(this.syncReadItems, bufferType_1.default.ARRAY_ARRAY);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.deviceType = this.popByte();
        var byteItems = this._popArrayArray();
        for (var i = 0; i < byteItems.length; i++) {
            this.syncReadItems.push((new KFSession.KFSyncReadItem().parserFromBuffer(byteItems[i])));
        }
    }
});
KFSession.KFSyncReadKF = protocol_1.default.Response.extend({
    category: 'KF',
    uri: kefu_constant_1.default.KF.URI_KF_SYNC_READ_KF,
    init: function () {
        this.uid = 0;
        this.deviceType = deviceInfo_1.default.deviceType;
        this.syncReadItems = [];
    },
    marshall: function () {
        this.push(this.uid, bufferType_1.default.LONG);
        this.push(this.deviceType, bufferType_1.default.BYTE);
        this.push(this.syncReadItems, bufferType_1.default.ARRAY_ARRAY);
    },
    unmarshall: function () {
        this.uid = this.popLong().value();
        this.deviceType = this.popByte();
        var byteItems = this._popArrayArray();
        for (var i = 0; i < byteItems.length; i++) {
            this.syncReadItems.push((new KFSession.KFSyncReadItem().parserFromBuffer(byteItems[i])));
        }
    }
});
KFSession.KFSyncReadItem = protocol_1.default.Response.extend({
    category: 'KF',
    uri: kefu_constant_1.default.KF.URI_KF_SYNC_READ_ITEM,
    init: function () {
        // chatId
        this.chatId = '';
        // 会话对方UID
        this.peerUid = '';
        // 最新的时间戳
        this.peerAppId = 0;
        this.stamp = '';
        this.channel = 0;
    },
    marshall: function () {
        this.push(this.chatId, bufferType_1.default.LONG);
        this.push(this.peerUid, bufferType_1.default.LONG);
        this.push(this.peerAppId, bufferType_1.default.SHORT);
        this.push(this.stamp, bufferType_1.default.LONG);
        this.push(this.channel, bufferType_1.default.SHORT);
    },
    unmarshall: function () {
        this.chatId = this.popLong().value();
        this.peerUid = this.popLong().value();
        this.peerAppId = this.popShort();
        this.stamp = this.popLong().value();
        this.channel = this.popShort();
    }
});
/**
 * 通知消息
 */
KFSession.KFNotice = protocol_1.default.Response.extend({
    category: 'KF',
    uri: kefu_constant_1.default.KF.URI_KF_NOTICE,
    init: function () {
        this.toUid = 0;
        this.type = 0;
        this.data = '';
        this.cts = timer_1.default.get();
        this.channel = 0;
    },
    marshall: function () {
        this.push(this.toUid, bufferType_1.default.LONG);
        this.push(this.type, bufferType_1.default.INT);
        this.push(this.data, bufferType_1.default.STRING);
        this.push(this.cts, bufferType_1.default.LONG);
        this.push(this.channel, bufferType_1.default.SHORT);
    },
    unmarshall: function () {
        this.toUid = this.popLong().value();
        this.type = this.popInt();
        this.data = this.popString();
        this.cts = this.popLong().value();
        this.channel = this.popShort();
    }
});
exports.default = KFSession;


//# sourceURL=webpack://MTDX/./src/core/kefu/kefu.session.ts?